package mo.leetcode_top;

import java.util.Random;

public class L384 {

    private int[] nums;
    private int[] original;
    private Random random;

    public L384(int[] nums) {
        this.nums = nums;
        this.original = new int[nums.length];
        System.arraycopy(nums, 0, original, 0, nums.length);
        random = new Random();
    }

    public int[] reset() {
        System.arraycopy(original, 0, nums, 0, original.length);
        return nums;
    }

    public int[] shuffle() {
        for (int i = 0; i < nums.length - 1; i++) {
            int j = i + random.nextInt(nums.length-i);
            int tmp = nums[i];
            nums[i] = nums[j];
            nums[j] = tmp;
        }
        return nums;
    }

}
